package com.csu.springbootpetstore.service;

import com.csu.springbootpetstore.mapper.UserMapper;
import com.csu.springbootpetstore.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    public List<User> getUserByUsername(String username) {
        Map<String,Object> userMap = new HashMap<>();
        userMap.put("username",username);
        List<User> users = userMapper.selectByMap(userMap);
        return users;
    }

    @Override
    public String isRightOfUser(String username, String password) {
        List<User> users = getUserByUsername(username);
        if (users.size() == 0)
            return "用户名错误！";
        User user = users.get(0);
        if (user.getPassword().equals(password))
            return "success";
        else
            return "密码错误！";
    }
}
